function handleEvent (event) {
  let touches = event.touches
  let timeStamp = event.timeStamp
  if (touches.length == null) {
    throw new Error('Invalid touch list: ' + touches)
  }
  if (timeStamp instanceof Date) {
    timeStamp = timeStamp.valueOf()
  }
  if (typeof timeStamp !== 'number') {
    throw new Error('Invalid timestamp value: ' + timeStamp)
  }
  return {touches, timeStamp}
}

let store = {}

export default {
  handleTouchStart (event) {
    if (this.scrollTop > 20) {
      this.statusTop = 'default'
      return
    }
    const eventData = handleEvent(event)
    let touches = eventData.touches
    let timeStamp = eventData.timeStamp

    var currentTouchLeft, currentTouchTop
    var isSingleTouch = touches.length === 1
    if (isSingleTouch) {
      currentTouchLeft = touches[0].pageX
      currentTouchTop = touches[0].pageY
    } else {
      currentTouchLeft = Math.abs(touches[0].pageX + touches[1].pageX) / 2
      currentTouchTop = Math.abs(touches[0].pageY + touches[1].pageY) / 2
    }

    store.startPullRefresh = true
    this.statusTop = 'pulling'
    store.startX = currentTouchLeft
    store.startY = currentTouchTop
    store.startTimeStamp = timeStamp
    store.minHeightCanPullRefresh = 40 * (window.dpr || 1)
  },
  handleTouchMove (event) {
    if (this.scrollTop >= 20) {
      return
    }
    const eventData = handleEvent(event)
    let touches = eventData.touches
    let timeStamp = eventData.timeStamp
    let currentTouchTop
    if (touches.length === 2) {
      currentTouchTop = Math.abs(touches[0].pageY + touches[1].pageY) / 2
    } else {
      currentTouchTop = touches[0].pageY
    }
    let moveY = (currentTouchTop - store.startY) / 2
    store.movedY = moveY
    if (moveY < 0) {
      store.startPullRefresh = false
    }
    // 如果是下来刷新
    if (store.startPullRefresh) {
      event.preventDefault()
      let el = this.$refs['innerWrapRef']
      el.style.transition = `${timeStamp - store.timeStamp}ms linear`
      el.style.transform = `translateY(${moveY}px)`
      let arrowEl = this.$refs['arrowRef']
      if (moveY >= store.minHeightCanPullRefresh) {
        arrowEl.style.transform = `rotate(180deg)`
        arrowEl.canPullRefresh = true
        this.statusTop = 'pullingEnable'
      } else {
        arrowEl.style.transform = `rotate(0deg)`
        arrowEl.canPullRefresh = false
        this.statusTop = 'pulling'
      }
    }
  },
  handleTouchEnd (event) {
    // 如果是下来刷新
    let el = this.$refs['innerWrapRef']
    el.style.transition = `.15s linear`
    let arrowEl = this.$refs['arrowRef']
    arrowEl.style.transform = `rotate(0deg)`
    if (arrowEl.canPullRefresh) {
      this.handlePullRefresh()
      el.style.transform = `translateY(${store.minHeightCanPullRefresh}px)`
    } else {
      el.style.transform = `translateY(0px)`
    }
    store = {}
    arrowEl.canPullRefresh = false
  }
}
